package beer.coder.imageviewer;

import java.io.File;
import java.nio.file.Paths;
import javafx.scene.image.Image;
import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;

/**
 * TODO
 *
 * @author amath0312
 * @version 1.0
 * @date 2020-11-01 16:25
 */
public class ImageViewerUtil {

  public static Image loadImage(File file) {
    return new Image(file.toURI().toString());
  }

  public static Image makeEmptyImage(int w, int h) {
    WritableImage image = new WritableImage(w, h);
    for (int x = 0; x < w; x++) {
      for (int y = 0; y < h; y++) {
        image.getPixelWriter().setColor(x, y, Color.ANTIQUEWHITE);
      }
    }

    return image;
  }


  public static String nameOfImage(String imagePath) {
    if (imagePath == null) {
      return "*";
    } else {
      return Paths.get(imagePath).getFileName().toString();
    }
  }

  public static String titleOfImage(Image image, String name) {
    return name
        + " - " + (int) image.getWidth() + " x " + (int) image.getHeight()
        + " - ImageViewer(beer.coder)";
  }
}
